# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-cliargs
_pkgname=lua_cliargs
pkgver=3.0_p2
_pkgver=${pkgver%_p*}-${pkgver##*_p}
pkgrel=0
pkgdesc="A command-line argument parsing module for Lua"
url="https://github.com/amireh/lua_cliargs"
arch="noarch"
license="MIT"
source="$pkgname-$pkgver.tar.gz::https://github.com/amireh/$_pkgname/archive/v$_pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$_pkgver"

_luaversions="5.1 5.2 5.3"
for _v in $_luaversions; do
	makedepends="$makedepends luarocks$_v"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$_pkgver"

	cd "$builddir"

	luarocks-$lver install \
		--deps-mode=none \
		--tree="$subpkgdir/usr" \
		$_pkgname-$_pkgver.rockspec

	rm -r "$rockdir"/../../manifest "$rockdir"/doc
}

sha512sums="e7a475f1d41249b0a35f021a6ccca46078f5b689c1927a4dd4cab80b2e4d291babaab35cf7d64fad3ebf68d871fb5177f030c7a2b28d9f55fbeb4dd26021d024  lua-cliargs-3.0_p2.tar.gz"
